﻿using Hotel.DAL;
using Hotel.Model.Discount;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hotel.BLL
{
    public class DiscountBLL
    {
        DiscountDAL dal;
        public DiscountBLL(DiscountDAL dal) {
        
            this.dal = dal;
        }

        /// <summary>
        /// 增加优惠券
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public int PostAddDiscount(T_Discount info)
        {
            try
            {
                int r = dal.SeachDiscountTile(info.D_Title);
                if(r > 0 )
                {
                    return -1;
                }
                else
                {
                    int res = dal.PostAddDiscount(info);
                    if(res > 0)
                    {
                        return 1;
                    }
                    else
                    {
                        return -2;
                    }
                }
                
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 获取优惠券类型列表
        /// </summary>
        /// <returns>返回符合条件的数据</returns>
        public List<T_Discount_Type> GetDiscountTypeList()
        {
            try
            {
                List<T_Discount_Type> list = dal.GetDiscountTypeList();
                return list;
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 获取所有门店
        /// </summary>
        /// <param name="totalPage"></param>
        /// <param name="totalCount"></param>
        /// <param name="Ddid"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public IQueryable GetDiscountList(out int totalPage, out int totalCount, int? DTid = null, int pageIndex = 1, int pageSize = 2)
        {
            try
            {
                var list = dal.GetDiscountList(out totalPage, out totalCount, DTid, pageIndex, pageSize) ;

                return list;
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 查询所有使用过的优惠券
        /// </summary>
        /// <returns></returns>
        public IQueryable GetDiscountUsed()
        {
            try
            {
                var list = dal.GetDiscountUsed();

                return list;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
